//
//  EaTabBar.m
//  EaWeibo
//
//  Created by xalo on 16/7/8.
//  Copyright © 2016年 Eason. All rights reserved.
//

#import "DZZTabBar.h"

@interface DZZTabBar ()

@property (nonatomic,strong)UIButton *plusButton;

@end

@implementation DZZTabBar

- (UIButton *)plusButton{
    if (!_plusButton) {
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_icon_add"] forState:UIControlStateNormal];
        [btn setImage:[UIImage imageNamed:@"tabbar_compose_background_icon_add"] forState:UIControlStateHighlighted];
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"tabbar_compose_button_highlighted"] forState:UIControlStateHighlighted];

//        默认按钮的尺寸跟背景图片一样大
//        sizeToFit:默认会根据按钮的背景图片或者image和文字计算出最合适的尺寸
        [btn sizeToFit];
        _plusButton = btn;
        [self addSubview:_plusButton];
        
        
    }
    return _plusButton;
}
//调整子控件的位置
- (void)layoutSubviews{
    [super layoutSubviews];
    
//    调整系统自带的tabBar上的按钮位置
    CGFloat btnX = 0;
    CGFloat btnY = 0;
    CGFloat btnW = self.bounds.size.width/(self.items.count+1);
    CGFloat btnH = self.bounds.size.height;
    
    
    int i = 0;
//    调整系统自带的tabBar上按钮的位置
    for (UIView *tabBarbutton in self.subviews) {
//        判断下面是否是UITabBarButton
        if ([tabBarbutton isKindOfClass:NSClassFromString(@"UITabBarButton")]) {
            if (i == 2) {
                i = 3;
            }
            btnX = i*btnW;
            tabBarbutton.frame = CGRectMake(btnX, btnY, btnW, btnH);
            i++;
        }
    }
//     设置按钮的位置
    self.plusButton.center = CGPointMake(self.bounds.size.width/2, self.bounds.size.height/2);
    
    
    
    
    
}




@end
